<?
// +----------------------------------------------------------------------
// | 访问记录，记录敏感操作，例如：退款操作 
// +----------------------------------------------------------------------
// | Author: TongBC <50249101@qq.com>
// +----------------------------------------------------------------------
// | Date  : 2015/01/23
// +----------------------------------------------------------------------
// | table : pft_access_log
// +----------------------------------------------------------------------

class AccessRecord{

	const ACTION_REFUND             = 1;//退款
    const ACTION_GET_MONEY          = 2;//提现
    const ACTION_MODIFY_SMS_TPL     = 3;//修改短信模板
    const ACTION_REFUND_MANUAL      = 4;//手工退款记录
    const ACTION_MODIFY_TERMINAL    = 5;//产品终端验证设置
	const ACTION_MODIFY_PRICE       = 6;//供应商修改门票价格
	const ACTION_DELETE_ACCOUNT     = 7;//删除系统账号
	// const ACTION_RESET_PASSWORD     = 8;//重置系统账号

    public static function insert($action,$mark, $db=null){
		$mid = $_SESSION['memberID'];// 平台账号
		$remote_addr = self::remote_address();// 访问地址
		$ins = <<<SQL
insert into `pft_access_log` set `access_time`=now(),`mid`='$mid',
`access_ip`='$remote_addr',`access_action`=$action,`access_note`='$mark'
SQL;
        if (!is_null($db)) {
            return $db->exec($ins);
        }
		return $GLOBALS['le']->query($ins);
	}
	
	public static function remote_address(){
		if(getenv("HTTP_CLIENT_IP")) return getenv("HTTP_CLIENT_IP");
		if(getenv("HTTP_X_FORWARDED_FOR")) return getenv("HTTP_X_FORWARDED_FOR");
		if(getenv("REMOTE_ADDR")) return getenv("REMOTE_ADDR");
	}
}

// CREATE TABLE `pft_access_log` (
  // `id` int(10) NOT NULL AUTO_INCREMENT,
  // `mid` int(10) unsigned not null,/*操作人员ID*/
  // `access_ip` varchar(50) NOT NULL,/*访问IP*/
  // `access_time` datetime NOT NULL,/*操作时间*/
  // `access_note` varchar(100) NOT NULL,/*备注说明,如：退款|订单号123456|操作账号600001*/
  // `access_action` tinyint(1) unsigned NOT NULL,/*操作类型，配置在数组中*/
  // PRIMARY KEY(`id`)
// ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
?>